package com.finance.cooperate.feature.service.impl;

import com.finance.cooperate.common.utils.StringUtil;
import com.finance.cooperate.dao.entity.primary.Personal;
import com.finance.cooperate.dao.local.scope.CooperateRequestScope;
import com.finance.cooperate.dao.repository.primary.PersonalRepository;
import com.finance.cooperate.feature.dto.PersonalDTO;
import com.finance.cooperate.feature.service.PersonalService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName PersonalServiceImpl
 * @Description TODO
 * @Author shen
 * @Date 2023/8/7 09:49
 * @Modify ...
 */
@Slf4j
@Service
public class PersonalServiceImpl implements PersonalService {

    @Autowired
    private CooperateRequestScope requestScope;

    @Autowired
    private PersonalRepository personalRepository;

    @Override
    public PersonalDTO getInfo(String uid) {

        PersonalDTO dto = new PersonalDTO();

        String applyId = requestScope.getApplyId();

        List<Personal> personalList = personalRepository.findByApplyId(applyId);

        if (personalList.size() > 0) {
            Personal personal = personalList.get(0);

            String maritalStatus = personal.getMaritalStatus();
            dto.setMaritalStatus(StringUtil.digitalExtraction(maritalStatus));

            String highestSchoolRecord = personal.getHighestSchoolRecord();
            dto.setHighestSchoolRecord(StringUtil.digitalExtraction(highestSchoolRecord));

            String residentialType = personal.getResidentialType();
            dto.setResidentialType(StringUtil.digitalExtraction(residentialType));

            String residentialDetailAddress = personal.getResidentialDetailAddress();
            if (!StringUtil.isEmptyOrNvl(residentialDetailAddress)) {
                dto.setResidentialDetailAddressLen(residentialDetailAddress.length());
            }


        }


        return dto;
    }
}
